﻿<UserControl x:Class="navigation.Controls.ScrumBoardTasksContainer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:s="http://schemas.microsoft.com/surface/2008"
             mc:Ignorable="d" 
             x:Name="TasksContainer">
    <UserControl.Resources>
        <DataTemplate x:Key="ListBoxItemTemplete">
            <Canvas x:Name="stackPanel" Height="120" Width="120">
                <Label 
                        Content="{Binding TaskName}" 
                        Foreground="Black"
                        Background="AntiqueWhite"
                        HorizontalAlignment="Center" 
                        VerticalAlignment="Center"
                        FontSize="20"
                        Width="110"
                        Height="110"/>
            </Canvas>
        </DataTemplate>

        <Style x:Key="CursorStyle" TargetType="{x:Type ContentControl}">
            <Setter Property="ContentTemplate" Value="{StaticResource ListBoxItemTemplete}" />
            <Setter Property="BorderThickness" Value="9"/>
            <Setter Property="BorderBrush" Value="{DynamicResource {x:Static s:SurfaceColors.Accent1BrushKey}}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ContentControl}">
                        <Border 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            BorderBrush="{TemplateBinding BorderBrush}">
                            <ContentPresenter Margin="0"
                                Content="{TemplateBinding Content}" 
                                ContentTemplate="{TemplateBinding ContentTemplate}">
                            </ContentPresenter>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="Tag" Value="CanDrop">
                    <Setter Property="BorderBrush" Value="{DynamicResource {x:Static s:SurfaceColors.Accent4BrushKey}}" />
                </Trigger>
                <Trigger Property="Tag" Value="CannotDrop">
                    <Setter Property="BorderBrush" Value="{DynamicResource {x:Static s:SurfaceColors.Accent3BrushKey}}" />
                </Trigger>
            </Style.Triggers>
        </Style>
       
        <Style TargetType="ListBoxItem" x:Key="ContainerStyle">
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border Name="Border" Padding="2" SnapsToDevicePixels="true">
                            <ContentPresenter/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Grid>
        <s:SurfaceListBox Name="TasksListBox" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}" ItemContainerStyle="{StaticResource ContainerStyle}"
                          AllowDrop="True" ItemsSource="{Binding ElementName=TasksContainer, Path=Items}" Margin="0,0,0,0" Visibility="Visible"                     
                          PreviewTouchDown="OnDragSourcePreviewTouchDown" 
                          s:SurfaceDragDrop.Drop="TasksListBox_OnDropTargetDrop"
                          s:SurfaceDragDrop.DragCanceled="TasksListBox_DragCanceled"
                          s:SurfaceDragDrop.DragCompleted="TasksListBox_DragCompleted"
                          s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                          s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                          >
            <s:SurfaceListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" ItemHeight="130" ItemWidth="130" IsItemsHost="True" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=s:SurfaceListBox, AncestorLevel=1}, Path=ActualWidth}"/>
                </ItemsPanelTemplate>
            </s:SurfaceListBox.ItemsPanel>
        </s:SurfaceListBox>

        <s:LibraryStack Name="TasksStack" Background="Transparent" Margin="2" MinHeight="100" Height="100" Visibility="Collapsed" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}"
                        AllowDrop="True" ItemsSource="{Binding ElementName=TasksContainer, Path=Items}"                      
                        PreviewTouchDown="LibraryStackPreviewTouchDown" 
                        s:SurfaceDragDrop.DragCanceled="TasksListBox_DragCanceled"
                        s:SurfaceDragDrop.DragCompleted="TasksListBox_DragCompleted"
                        s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                        s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                        >
        </s:LibraryStack>
    </Grid>
</UserControl>
